﻿using Blm.Utils.Extensions;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Sys;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Applet.RequestDto;
using VisionCloud.Domain.DtoModel.Applet.ResponseDto;
using VisionCloud.Domain.DtoModel.Sys;
using VisionCloud.Domain.Extension;
using VisionCloud.Domain.Repository.Interface.Sys;

namespace VisionCloud.Domain.Repository.Implement.Sys
{
    public class SysWxMessageRepository : BaseRepository<SysWxMessage>, ISysWxMessageRepository
    {
        /// <summary>
        /// 根据Id获取所有微信信息，包含子信息
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<SysWxMessage>> GetSysWxMessageList(WxMessageDto query)
        {
            var result = await (
              from h in Db.SysWxMessages
              where !h.IsDeleted 
              && (string.IsNullOrWhiteSpace(query.Id) || h.Id == query.Id || h.ParentId == query.Id)
              && (h.Type == query.Type || query.Type == -1)
              select h
             ).AsNoTracking().ToListAsync().ConfigureAwait(false);
            return result;
        }
    }
}